package net.hnjdzy.newsclient;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends Activity {
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);

        mViewPager = findViewById(R.id.viewPager);
        mViewPager.setAdapter(new MyPageAdapter());
    }

    public void gotoMainClick(View view){
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
    }
    //ViewPager的适配器
    class MyPageAdapter extends PagerAdapter{
        private List<View> mViews;

        MyPageAdapter(){
            mViews = new ArrayList<>();
            View view1 = getLayoutInflater().inflate(R.layout.ad1_layout,null);
            View view2 = getLayoutInflater().inflate(R.layout.ad2_layout,null);
            mViews.add(view1);
            mViews.add(view2);
        }

        @Override
        public int getCount() {
            return mViews.size();
        }

        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
            return view == object;
        }

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            container.addView(mViews.get(position));
            return mViews.get(position);
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            container.removeViewAt(position);
        }
    }
}
